package com.yikaiye.android.yikaiye.ui.activity.order.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.di.retrofit.BaseModel;
import com.yikaiye.android.yikaiye.di.retrofit.BaseNetCallback;
import com.yikaiye.android.yikaiye.model.OrderProgressModel;
import com.yikaiye.android.yikaiye.utils.ToastHelper;

import java.util.List;

public class OrderProgressViewModel extends BaseViewModel {

    public MutableLiveData<List<OrderProgressModel>> progressDataMutableLiveData = new MutableLiveData<>();

    /**
     * 查询订单关联服务
     *
     * @param orderId 订单id
     */
    public void getServiceByOrderId(String orderId) {
        addSubscribe(mRetrofitHelper.getServiceByOrderId(orderId).subscribeWith(new BaseNetCallback<List<OrderProgressModel>>() {

            @Override
            public void onSuccess(BaseModel<List<OrderProgressModel>> baseModel) {
                if (baseModel.getCode() == Constant.SUCCESS) {
                    progressDataMutableLiveData.setValue(baseModel.getData());
                } else {
                    ToastHelper.show(baseModel.getMsg());
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                ToastHelper.show(message);
            }
        }));
    }
}
